package com.snail.service.impl;

import com.snail.dao.SellerInfoDao;
import com.snail.entity.SellerInfo;
import com.snail.enums.ResultEnum;
import com.snail.exception.SellException;
import com.snail.service.SellerInfoService;
import com.snail.utils.MD5Util;
import com.snail.utils.ResultVOUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;

/**
 * @Author 【swg】.
 * @Date 2017/12/11 20:15
 * @DESC
 * @CONTACT 317758022@qq.com
 */
@Service
@Slf4j
public class SellerInfoServiceImpl implements SellerInfoService{
    @Autowired
    private SellerInfoDao sellerInfoDao;

    @Override
    public SellerInfo check(String username,String password) throws UnsupportedEncodingException, NoSuchAlgorithmException,SellException {
        SellerInfo sellerInfo = sellerInfoDao.findByUsername(username);
        if(sellerInfo == null){
            log.error("【获取用户失败】,username={}",username);
            throw new SellException(ResultEnum.LOGIN_FAIL);
        }
        String dbPasswd = sellerInfo.getPassword();
        if(!MD5Util.checkPassword(password,sellerInfo.getPassword())){
            log.error("【密码比对不正确】,username={}",username);
            throw new SellException(ResultEnum.LOGIN_FAIL);
        }
        return sellerInfo;
    }
}
